#!/usr/bin/env bash
################################################################################
# cig - keep track of how much you smoke                                       #
#                                                                              #
# @author    David Christian Liedle <david.liedle@gmail.com>                   #
# @copyright Copyright (c) 2009-2011 David Christian Liedle                    #
# @license   MIT Open Source License / CC-BY 3.0                               #
#             http://www.opensource.org/licenses/mit-license.php               #
#              http://creativecommons.org/licenses/by/3.0/                     #
#                                                                              #
#  Released as part of The CLIMAX/Candy Suite: http://climax.googlecode.com/   #
#                                                                              #
################################################################################
# USAGE
# options:  -h help
#           -k kind
#           -r remove ( remove ~/.cig file )
#           -t time ( make an entry for another time than now )
#           -u undo ( remove that last entry )
#           -v version ( prints version number and exits )
#
# DEVELOPMENT HISTORY
# Created: 2008.10.06 - Version 1.0
# Updated: 2009.01.26 - Candy Suite formatting (comments only; no code changes)
#
# Note: Use the companion program `cigs` to view the log(s) generated by this.
################################################################################

CIGVERSION="cig - 1.0 (2008.10.06)"

# # # Check for existing file # # #

if [ ! -f ~/.cig ]; then
    touch ~/.cig
fi

# # # Handle CLI Options: # # #
if [ $# -gt 0 ]; then
    
    if [ $1 = "-h" ]; then
        echo "usage: cig [-hkrtuv]"
        echo "            -h help"
        echo "            -k kind"
        echo "            -r remove"
        echo "            -t time"
        echo "            -u undo"
        echo "            -v version"
        exit 0
    fi
    
    if [ $1 = "-k" ]; then
        echo "set the kind - not yet implemented. no changes made."
        exit 0
    fi
    
    if [ $1 = "-r" ]; then
        echo -n "Really remove your ~/.cig file? (Sent to ~/.Trash) yes / no : "
        read ranswer
        if [ $ranswer = "yes" ]; then
            echo "Moving ~/.cig to the trash..."
            mv ~/.cig ~/.Trash/
        else
            echo "Operation cancelled - everything left as-is."
        fi
    fi
    
    if [ $1 = "-t" ]; then
        echo "specify a different time than now - not yet implemented. no changes made."
        exit 0
    fi
    
    if [ $1 = "-u" ]; then
        echo "undo last entry - not yet implemented. no changes made."
        exit 0
    fi
    
    if [ $1 = "-v" ]; then
        echo $CIGVERSION
        exit 0
    fi
    
else
    # no args: add a single entry
    date >> ~/.cig
    echo "entry added for" `date`
fi
